<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-ecrMerchant-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">电话：</label>
				<div class="col-sm-8">
					<input id="phone" name="phone" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">储蓄卡账号：</label>
				<div class="col-sm-8">
					<input id="bankAccount" name="bankAccount" class="form-control"
						type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">身份证编号：</label>
				<div class="col-sm-8">
					<input id="idCardNumber" name="idCardNumber" class="form-control"
						type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group" id="invokeDiv" style="display: none;">
				<label class="col-sm-3 control-label">是否认证：</label>	
				<div class="col-sm-8">
					<div class="radio-box">
						<label>
							<input type="radio" value="0" th:id="type1" name="type" checked="checked"> 仍需认证
						</label>
					</div>
					<div class="radio-box">
						<label>
							<input type="radio" value="1" th:id="type2" name="type"> 无需认证
						</label>	
					</div>
				</div>
			</div>

		</form>
	</div>
	<div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/ecrMerchantForDLS"
		$("#form-ecrMerchant-add").validate({
			rules:{
				phone:{
					required:true,
					isPhone:true
				},
				name:{
					required:true,
					minlength: 2,//最小长度
					maxlength: 25 //最大长度
				},
				bankAccount:{
					required:true,
					digits:true,  //必须为数字
					minlength: 10,//最小长度
        			maxlength: 25 //最大长度
				},
				idCardNumber:{
					required:true,
					isIdentity:true//校验身份证号
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	var type = $('input[name="type"]:checked').val(); 
		       	  $.ajax({
		  		         url:prefix + "/add", //添加用户
		  		        dataType:"json",
		  		        type: "post",
		  		    	data:	{
		  	 		       	"phone":$("#phone").val(),
		  	 		       	"name":$("#name").val(),
		  	 		       	"bankAccount":$("#bankAccount").val(),
		  	 		       	"remark":$("#remark").val(),
		  	 		       	"idCardNumber":$("#idCardNumber").val(),
		  	 		       	"idCardNumber":$("#idCardNumber").val(),
		  	 		       	"type":type
		  	 		       	},
		  		          success:function(re){
		  		        	//认证失败
		  		        	 if(re.code=="0"){
		 						$.modal.msgSuccess(re.msg);
		 						//刷新表格
		 						$.operate.successCallback(re);
		 					//实名验证未通过	
	 						}else if(re.code=="1"){
							 	$.modal.alertError(re.msg);
							 	//显示选择是否实名认证按钮
							 	$("#invokeDiv").show();
							 	return;
							}else if(re.code=="2"){
								$.modal.alertError(re.msg);
								return;
							}
			        } 
			   });
	          /*  $.operate.save(prefix + "/add", $('#form-ecrMerchant-add').serialize()); */
	        }
	    }
	</script>
</body>
</html>
